package view;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;

import players.Player;


/**
 * This class is a useful utility for quickly and simply changing "skins" on different graphical elements.
 * A skin is created with specified "themes" and is then contained by a class.  
 * When the class requests a graphical element, like a picture, the skin returns a themed image, 
 * based on the settings at its construction.
 * @author Sacha, Ben
 */
public class Skin
{
	/**
	 * String instance variables that hold the settings for an instance of a Skin.
	 */
	public String white, black, background, highlight;
	
	/**
	 * The various BufferedImages that the Skin holds and can return when called upon.
	 * The image itself varies based on the String settings.
	 */
	private BufferedImage wBishop, wKing, wKnight, wPawn, wRook, wQueen, wBackground;
	private BufferedImage bBishop, bKing, bKnight, bPawn, bRook, bQueen, bBackground;
	private BufferedImage highlightImage;

	public Color whiteBackground, blackBackground, highlightBackground;

	/**
	 * This constructor takes four settings and loads different images into its instance variable depending on them
	 * The BufferedImages can then be returned to give a unique image based on the Skin's settings.
	 * @param white - White theme
	 * @param black - Black theme
	 * @param background - Background theme
	 * @param highlight - Highlight theme
	 */
	public Skin(String white, String black, String background, String highlight)
	{
		this.white = white;
		this.black = black;
		this.background = background;
		this.highlight = highlight;
		try
		{
			this.wBishop = ImageIO.read(new File("skins/" + white + "/Bishop.png"));
			this.wKing = ImageIO.read(new File("skins/" + white + "/King.png"));
			this.wKnight = ImageIO.read(new File("skins/" + white + "/Knight.png"));
			this.wPawn = ImageIO.read(new File("skins/" + white + "/Pawn.png"));
			this.wQueen = ImageIO.read(new File("skins/" + white + "/Queen.png"));
			this.wRook = ImageIO.read(new File("skins/" + white + "/Rook.png"));
			
			this.bBishop = ImageIO.read(new File("skins/" + black + "/Bishop.png"));
			this.bKing = ImageIO.read(new File("skins/" + black + "/King.png"));
			this.bKnight = ImageIO.read(new File("skins/" + black + "/Knight.png"));
			this.bPawn = ImageIO.read(new File("skins/" + black + "/Pawn.png"));
			this.bQueen = ImageIO.read(new File("skins/" + black + "/Queen.png"));
			this.bRook = ImageIO.read(new File("skins/" + black + "/Rook.png"));
			
			this.wBackground = ImageIO.read(new File("skins/" + background + "/White.jpg"));
			this.bBackground = ImageIO.read(new File("skins/" + background + "/Black.jpg"));
			
			highlightImage = ImageIO.read(new File("skins/" + highlight + "/Highlight.jpg"));
		}
		catch (IOException e) {}
		
		whiteBackground = new Color(wBackground.getRGB(0, 0));
		blackBackground = new Color(bBackground.getRGB(0, 0));
		highlightBackground = new Color(highlightImage.getRGB(0,0));
	}

	public String getHighlight() {
		return highlight;
	}

	public String getWhite() {
		return white;
	}

	public String getBlack() {
		return black;
	}

	public String getBackground() {
		return background;
	}

	public BufferedImage getBishop(int color) {
		if(color == Player.WHITE)
			return wBishop;
		else
			return bBishop;
	}

	public BufferedImage getKing(int color) {
		if(color == Player.WHITE)
			return wKing;
		else
			return bKing;
	}

	public BufferedImage getKnight(int color) {
		if(color == Player.WHITE)
			return wKnight;
		else
			return bKnight;
	}

	public BufferedImage getPawn(int color) {
		if(color == Player.WHITE)
			return wPawn;
		else
			return bPawn;
	}

	public BufferedImage getRook(int color) {
		if(color == Player.WHITE)
			return wRook;
		else
			return bRook;
	}

	public BufferedImage getQueen(int color) {
		if(color == Player.WHITE)
			return wQueen;
		else
			return bQueen;
	}
	
	public Color getWhiteBackground() {
		return whiteBackground;
	}
	
	public Color getBlackBackground() {
		return blackBackground;
	}
	
	public Color getHighlightBackground() {
		return highlightBackground;
	}
}
